cmake_minimum_required(VERSION 3.0.2)
project(superglue)

## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)

set(CMAKE_BUILD_TYPE Debug)


## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
        sensor_msgs
        cv_bridge
        image_transport
        message_generation
)

add_service_files(
        FILES
        SuperScore.srv
)
generate_messages(
        DEPENDENCIES
        std_msgs
        sensor_msgs
)


## System dependencies are found with CMake's conventions
find_package(OpenCV REQUIRED)



catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES superglue
  CATKIN_DEPENDS roscpp rospy std_msgs message_runtime
#  DEPENDS system_lib
)

###########
## Build ##
###########

#set(PYTHON_EXECUTABLE "/home/daybeha/anaconda3/envs/pytorch/bin/python")
set(PYTHON_INCLUDE_DIR "/home/daybeha/anaconda3/envs/pytorch/include/python3.9")
set(NUMPY_INCLUDE_DIR "/home/daybeha/anaconda3/envs/pytorch/include/python3.9/site-packages/numpy/core/include")
set(PYTHON_LIBRARY "/home/daybeha/anaconda3/envs/pytorch/lib/libpython3.9.so")
#set(SETUPTOOLS_DEB_LAYOUT OFF)

## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
 include
    models
        src/loopclose.h
  ${catkin_INCLUDE_DIRS}
        ${OpenCV_INCLUDE_DIRS}
#        "/usr/include/python3.6m"
        ${PYTHON_INCLUDE_DIR}
        ${NUMPY_INCLUDE_DIR}
)


#LINK_DIRECTORIES("/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu")
#LINK_DIRECTORIES("/home/daybeha/anaconda3/envs/pytorch/lib/python3.9/config-3.9-x86_64-linux-gnu")


add_executable(c_python src/c_python.cpp)
target_link_libraries(c_python
        ${catkin_LIBRARIES}
        ${OpenCV_LIBRARIES}

        -lpython3.6m
        )

add_executable(sg_cpy_test src/sg_cpy_test.cpp)
target_link_libraries(sg_cpy_test
        ${catkin_LIBRARIES}
        ${OpenCV_LIBRARIES}
#        -lpython3.6m
        ${PYTHON_LIBRARY}  # !!!
        )

add_library(${PROJECT_NAME} SHARED
        src/loopclose.cpp
        )

target_link_libraries(${PROJECT_NAME}
        ${catkin_LIBRARIES}
        ${OpenCV_LIBRARIES}
        #        -lpython3.6m
        ${PYTHON_LIBRARY}  # !!!

        ${PYTHON_LIBRARY}
        )
add_executable(cp_thread src/cp_thread.cpp)
target_link_libraries(cp_thread
        ${catkin_LIBRARIES}
        ${OpenCV_LIBRARIES}
        #        -lpython3.6m
        ${PYTHON_LIBRARY}  # !!!
#        ${PROJECT_NAME}
        )


add_executable(pub_img_sub_score ros_test/pub_img_sub_score.cpp)
add_executable(sub_img_pub_score ros_test/sub_img_pub_score.cpp)
target_link_libraries(pub_img_sub_score
        ${catkin_LIBRARIES}
        ${OpenCV_LIBRARIES}
        )
target_link_libraries(sub_img_pub_score
        ${catkin_LIBRARIES}
        ${OpenCV_LIBRARIES}
        )


add_executable(client ros_test/client.cpp)
add_executable(server ros_test/server.cpp)
add_dependencies(client ${PROJECT_NAME}_gencpp)
add_dependencies(server ${PROJECT_NAME}_gencpp)
target_link_libraries(client
        ${catkin_LIBRARIES}
        ${OpenCV_LIBRARIES}
        )
target_link_libraries(server
        ${catkin_LIBRARIES}
        ${OpenCV_LIBRARIES}
        )
## Declare a C++ library
# add_library(${PROJECT_NAME}
#   src/${PROJECT_NAME}/superglue.cpp
# )


#catkin_install_python(PROGRAMS
#        # predict
#        matching.py
#        script/sg_match.py
#        DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
#        )
#install(FILES
#        match_pairs
#        DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
#        )



catkin_install_python(PROGRAMS
        ros_test/server.py

        DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
        )
catkin_install_python(PROGRAMS
        ros_test/server_class.py
        DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
        )



#############
## Testing ##
#############

## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_superglue.cpp)
# if(TARGET ${PROJECT_NAME}-test)
#   target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()

## Add folders to be run by python nosetests
# catkin_add_nosetests(test)
